<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>javascript统计</title>
</head>
<body>

<input type="submit" name="dd" value="点击" onclick="show()">
<script>
    function show() {

        var a = "123456789123456789";
        var a1=a;
        var b = "123";
        var count = 0;
        var i = 0;
        for (i = 0; i <= a.length; i++) {

            if (a.indexOf(b) == i) {
                a = a.substring(i + 1, a.length);
                count++;
            }
        }
        alert(b+"在"+a1+"出现了"+count+"次");
    }

</script>

</body>
</html>

